﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UI.Forms
{
    public partial class 选择应付单据 : FormBase1
    {
        private Guid? clientid;
        BindingList<SVC.client.FK_D> fkd;

        public delegate void DoAction(List<SVC.client.FK_D> ds);//如果有参数的话，定义参数 

        public DoAction FatherRefresh;
        public 选择应付单据(Guid _clientid)
        {
            InitializeComponent();
            clientid = _clientid;
        }

        private void 选择应收单据_Load(object sender, EventArgs e)
        {
            fkd = new BindingList<SVC.client.FK_D>();
            fkd.Clear();
            gc_sk_D.DataSource = fkd;
            rlue_billtype.DataSource = my.bw.Bill_Get(my.ACID);
            if (clientid==null)
            {
                Comm.ShowAlert("请先选择客户！");
                this.Close();
            }
            else
            {

                if (clientid != null)
                {
                    
                    foreach (SVC.client.FK_D d in my.bw.getNotFK_By_ClientID(clientid.Value, my.ACID))
                    {
                        fkd.Add(d);
                    }

                }

            }
        }

        private void btn_ok_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {

            foreach (SVC.client.FK_D item in fkd)
            {
                int[] rowHandles = gridView1.GetSelectedRows();
                for (int i = 0; i < rowHandles.Length; i++)
                {
                    if (gridView1.GetRowCellValue(rowHandles[i], "billpid").ToString() == item.billpid)
                    {
                        item.selected = true;
                    }
                }

            }
            List<SVC.client.FK_D> ds =fkd.Where(p=>p.selected).ToList();
            //List<SVC.client.SK_D> ds = skd.ToList();
            FatherRefresh(ds);
            this.Close();
        }

        private void rce_selected_CheckedChanged(object sender, EventArgs e)
        {
            //this.gridView1.SelectRow(this.gridView1.FocusedRowHandle);
        }
    }
}
